import { http } from '@/utils/http'

/**
 * 用户服务协议
 * @returns Promise<IResData<RAgreement>>
 */
export function agreement(): Promise<IResData<RAgreement>> {
  return http.get('/api/nongshang/agreement')
}

/**
 * 手机验证码登录
 * @param params ILoginParams
 * @returns Promise<IResData<ILoginData>>
 */
export function loginByPhone(params: ILoginParams): Promise<IResData<ILoginData>> {
  return http.post('/api/nongshang/mobile_login', params, params)
}

/**
 * 用户注册
 * @param params IRegParams
 * @returns Promise<IResData<any>>
 */
export function register(params: IRegParams): Promise<IResData<any>> {
  return http.post('/api/nongshang/register', params, params)
}

/**
 * 获取微信openid
 * @param code string
 * @returns Promise<IResData<{ wx_openid: string }>>
 */
export function openId(code: string): Promise<IResData<{ wx_openid: string }>> {
  return http.post('/api/nongshang/wx_openid', { code }, { code })
}

/**
 * 微信登录
 * @param code string
 * @return Promise<IResData<ILoginData>>
 */
export function loginByWx(code: string): Promise<IResData<ILoginData>> {
  return http.post('/api/nongshang/wx_login', { code }, { code })
}

/**
 * 微信授权手机号登录
 * @param code
 */
export function loginByWxPhone(code: string): Promise<IResData<ILoginData>> {
  return http.post('/api/nongshang/get_mobile_login', { code }, { code })
}

// 手机验证码
export function sendCode(mobile: string): Promise<IResData<any>> {
  return http.post('/api/nongshang/get_code', { mobile }, { mobile })
}
